<?php

namespace Home\Model;

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Select;


class MenuTable extends AbstractTableGateway {

    protected $table = 'chuyenmuc';

    public function __construct(Adapter $adapter) {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new Menu());

        $this->initialize();
    }

    public function fetchAllDanhmuc(Select $select = null) {
        if (null === $select)
            $select = new Select();
        $select->from($this->table,array('*'))
				->where(array('theloai' => '5'))
				->join(
					'theloai',
					'theloai.id_theloai = chuyenmuc.theloai',
					array('*'));
        $resultSet = $this->selectWith($select);
        $resultSet->buffer();
        return $resultSet;
    }
	public function fetchAllCanbiet(Select $select = null) {
        if (null === $select)
            $select = new Select();
        $select->from($this->table,array('*'))
				->where(array('theloai' => '6'))
				->join(
					'theloai',
					'theloai.id_theloai = chuyenmuc.theloai',
					array('*'));
        $resultSet = $this->selectWith($select);
        $resultSet->buffer();
        return $resultSet;
    }
	public function fetchAllMenuchinh(Select $select = null) {
        if (null === $select)
            $select = new Select();
        $select->from($this->table,array('*'))
				->where(array('theloai != 6','theloai != 5'))
				->join(
					'theloai',
					'theloai.id_theloai = chuyenmuc.theloai',
					array('*'));
        $resultSet = $this->selectWith($select);
        $resultSet->buffer();
        return $resultSet;
    }
	public function getTenchuyenmuc($id) {
        $id = (string) $id;
		$select = new Select();
        $select->from($this->table)
				->where(array('duongdan' => $id));
        $resultSet = $this->selectWith($select);
        
        $row = $resultSet->current(); 
        return $row;
    }

    


}
